package menu;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class MenuNew extends JPanel implements MouseListener,Runnable{
	private static final long serialVersionUID = 1L;
	private int x=-500;
	private JLabel background;
	private boolean hide=false;
	
	public MenuNew()
	{
		super(true);
		this.setOpaque(false);
		this.setPreferredSize(new Dimension(600, 600));
		this.setBackground(new Color(0, 0, 0));
		
		
		URL url=MenuNew.class.getResource("/buttons/menuNew.png");
		background=new JLabel(new ImageIcon(url));
		background.setVisible(true);
		this.add(background);
		
		this.setVisible(true);
		
	}

	public void setHide(boolean value)
	{
		hide=value;
		if (value==false)
			x=-800;
		else
			x=600;
	}
	
	public void doMove()
	{
		System.out.println("PANNELLO IN MOVIMENTO!!");
		while (x<0)
		{
			x=x+10;
			this.setLocation(x, 200);
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
		}
	}
	
	public void doHide()
	{
		System.out.println("Pannello nascosto");
		while (x>0)
		{
			x=x-10;
			this.setLocation(x-600, 200);
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
		}
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void run() {
		if (hide==true){
			this.setVisible(true);
			doHide();}
		else{
			this.setVisible(true);
			doMove();}
	}

}
